/*************************************************************************
Hash ADT header file
Hashing function implementation
	Written By: Lam Lu
	Date: May/30/10
*************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif

#ifndef LAMHASH_H

#define LAHMHASH_H

/**************************************************************************
This function allocates the array of structure
	Pre: arr_size
	Post: Array of Structure is allocated/created
	Return: address of array of structure
**************************************************************************/
HASH* buildHash(int arr_size);

/**************************************************************************
The function insert  data into HashArray
	Pre: pHash( pointer to HashArray), pointer to string
	Post: data inserted
	Return: 1 if success, 0 otherwise
	Preconditions: pHash, string, soldier have been read/declared
**************************************************************************/
int insertHash(HASH* pHash, char* string, void* dataIn, int arr_size);

/*************************************************************************
The function searchs the data in Hash Array
	Pre: pHash( pointer to HashArray), key string, arr_size
	Reference parameters: targetIndex
	Post: targetIndex passed back to caller
	Return: 1 if found, 0 otherwise
	Preconditions: pHash, string, arr_size have been read
*************************************************************************/
int searchHash(HASH* pHash, char* string, int* targetIndex, int arr_size);

/*************************************************************************
The function deletes the data in Hash Array
	Pre: pHash( pointer to HashArray), key string, arr_size
	Reference parameters: deletedIndex, dataOut
	Post: target delelted, passed back the index of deleted target
		  and the pointer to target
	Return: 1 if success, 0 otherwise
	Preconditions: pHash, string, arr_size have been read
*************************************************************************/
int deleteHash(HASH* pHash, char* string, int* deletedIndex, void** dataOut,
			   int arr_size);

/**************************************************************************
The function determines the index to use for hash array
	Pre: pointer to string , arr_size
	Post: index determined
	Return: int(index)
	Preconditions: string is not empty
**************************************************************************/
int calIndex(char* string, int arr_size);

/**************************************************************************
The function solves collision using Variation of Linear Probe resolution
. Add 1, subtract 2, add 3, subtract 4, and so forth. It returns an int 
number to determine the next step(add or subtract the index)
	Pre: current home address, arr_size
    Reference parameters: jumper( to determine subtraction or addition)
	Post: new index determined
	Return: new index
	Preconditions: none
**************************************************************************/
int colResolution (int index, int* jumper, int arr_size);

/**************************************************************************
The function calculates the efficiency of the hash function: load factor,
records have collisions, longest collision path 
	Pre: hash array, arr_size
	Post: efficiency calculated
	Return: loadFactor, collsionCount, longestCol
	Preconditions: hash array is not empty
**************************************************************************/
void getEfficiency(HASH* pHash, double* loadFactor, int* collisionCount, 
				   int* longestCol,int arr_size);

/**************************************************************************
The function destroys hash array
	Pre: hash Array, pointer to function, arr_size
	Post: Hash destroyed
	Return: none
**************************************************************************/
void destroyHash(HASH* pHash,int arr_size, void (*freeMemory)(void* dataPtr));

/**************************************************************************
The function frees my memory
	Pre: pointer to dataOut
	Post: Hash destroyed
	Return: none
**************************************************************************/
void freeMemory(SOLDIER* dataOut);



#endif
#ifdef __cplusplus
}
#endif


